<!--
 * @Author: 冯尚新 fengshangxin@yunjinhz.com
 * @Date: 2023-05-23 10:51:57
 * @LastEditors: 冯尚新 fengshangxin@yunjinhz.com
 * @LastEditTime: 2023-06-07 14:59:43
 * @FilePath: \zmglpt-ui-mobile-v1.1\dev\pages\check\components\maintain-com.vue
 * @Description: 市管检查-信息维护组件
-->

<template>
  <view>
    <theme-navbar
      :isBack="true"
      :is-white="false"
      title="信息维护"
      :customBack="handlerBack"
      style="z-index: 99999"
    >
      <view class="nav-right-icon" v-if="!isDisabled" @tap="handlerSure">
        确定
      </view>
    </theme-navbar>
    <view>
      <u-form
        class="u-form-m fpad"
        :model="form"
        :error-type="['border-bottom', 'message']"
        label-position="top"
        label-width="auto"
        ref="uForm"
        :rules="rules"
      >
        <view v-for="(item, idx) in records" :key="idx">
          <!-- 开关选择 -->
          <u-form-item
            :label="item.itemName"
            :arrow="false"
            class="cell"
            :required="item.formItemProps.required"
            :prop="item.checkKey"
            v-if="item.operateType == '91401'"
          >
            <u-switch
              :disabled="isDisabled"
              slot="right-icon"
              v-model="form[item.checkKey]"
              @change="handlerSwitch"
            ></u-switch>
          </u-form-item>
          <!-- 选择框 -->
          <u-form-item
            :label="item.itemName"
            class="cell label-position-top"
            :arrow="false"
            :required="item.formItemProps.required"
            :prop="item.checkKeyLabel"
            v-if="item.operateType == '91402'"
          >
            <!-- slot="right-icon" -->
            <u-input
              :disabled="true"
              :placeholder="vaildUuidList(item.itemUuid) ? '' : '请选择'"
              :type="vaildUuidList(item.itemUuid) ? 'text' : 'select'"
              v-model="form[item.checkKeyLabel]"
              @tap="handlerSelShow(item)"
            />
          </u-form-item>
          <!-- 输入框 -->
          <u-form-item
            :label="item.itemName"
            :arrow="false"
            :required="item.formItemProps.required"
            :prop="item.checkKey"
            class="cell label-position-top"
            v-if="item.operateType == '91403'"
          >
            <!-- slot="right-icon" -->
            <u-input
              :disabled="isDisabled || vaildUuidList(item.itemUuid)"
              :type="item.inputType == 2 ? 'number' : 'text'"
              v-model="form[item.checkKey]"
              @blur="validText($event, item.checkKey)"
            />
          </u-form-item>
          <!-- 区划选择 -->
          <u-form-item
            :label="item.itemName"
            class="cell label-position-top"
            :arrow="false"
            :required="item.formItemProps.required"
            :prop="item.checkKeyLabel"
            v-if="item.operateType == '91406'"
          >
            <!-- slot="right-icon" -->
            <u-input
              :disabled="true"
              :placeholder="vaildUuidList(item.itemUuid) ? '' : '请选择'"
              :type="vaildUuidList(item.itemUuid) ? 'text' : 'select'"
              v-model="form[item.checkKeyLabel]"
              @tap="handlerAreaShow(item)"
            />
          </u-form-item>
          <!-- 从业人员登记 -->
          <view v-else-if="item.operateType == '91414'">
            <u-form-item
              class="cell cell-sub"
              :label="item.itemName"
              label-position="left"
              :required="item.formItemProps.required"
              :arrow="false"
            >
              <u-icon
                name="plus-circle"
                :color="!isDisabled ? $theme.u_type_primary : '#c0c0c0'"
                size="38"
                slot="right"
                @tap="handlerAddCy(item)"
              ></u-icon>
            </u-form-item>
            <!-- 从业人员 -->
            <sub-list-item
              :lists="cyPersons"
              :recordItemUuid="item.itemUuid"
              :isDisabled="isDisabled"
              @edit="handlerEditListItem"
              @del="handlerDelListItem"
            >
              <view class="title" slot-scope="d">
                {{ d.data.personName }}
              </view>
            </sub-list-item>
          </view>
          <!-- 仓储信息 -->
          <view v-else-if="item.operateType == '91415'">
            <u-form-item
              class="cell cell-sub"
              :label="item.itemName"
              label-position="left"
              :required="item.formItemProps.required"
              :arrow="false"
            >
              <u-icon
                name="plus-circle"
                :color="!isDisabled ? $theme.u_type_primary : '#c0c0c0'"
                size="38"
                slot="right"
                @tap="handlerAddStorage(item)"
              ></u-icon>
            </u-form-item>
            <!-- 仓储信息 -->
            <sub-list-item
              :lists="storages"
              :recordItemUuid="item.itemUuid"
              :isDisabled="isDisabled"
              @edit="handlerEditListItem"
              @del="handlerDelListItem"
            >
              <view class="title" slot-scope="d">
                {{ d.data.storageName }}
              </view>
            </sub-list-item>
          </view>
          <!-- 车辆信息 -->
          <view v-else-if="item.operateType == '91416'">
            <u-form-item
              class="cell cell-sub"
              :label="item.itemName"
              label-position="left"
              :required="item.formItemProps.required"
              :arrow="false"
            >
              <u-icon
                name="plus-circle"
                :color="!isDisabled ? $theme.u_type_primary : '#c0c0c0'"
                size="38"
                slot="right"
                @tap="handlerAddCar(item)"
              ></u-icon>
            </u-form-item>
            <!-- 车辆信息 -->
            <sub-list-item
              :lists="cars"
              :recordItemUuid="item.itemUuid"
              :isDisabled="isDisabled"
              @edit="handlerEditListItem"
              @del="handlerDelListItem"
            >
              <view class="title" slot-scope="d">
                {{ d.data.carNum }}
              </view>
            </sub-list-item>
          </view>
          <!-- 供货来源 -->
          <view v-else-if="item.operateType == '91418'">
            <u-form-item
              class="cell cell-sub"
              :label="item.itemName"
              :required="item.formItemProps.required"
              label-position="left"
              :arrow="false"
            >
              <u-icon
                name="plus-circle"
                :color="!isDisabled ? $theme.u_type_primary : '#c0c0c0'"
                size="38"
                slot="right"
                @tap="handlerAddSupply(item)"
              ></u-icon>
            </u-form-item>
            <!-- 供货来源信息 -->
            <sub-list-item
              :lists="supplyList"
              :recordItemUuid="item.itemUuid"
              :isDisabled="isDisabled"
              :isEdit="false"
              @del="handlerDelListItem"
            >
              <view class="title" slot-scope="d">
                {{ d.data.companyName }}
              </view>
            </sub-list-item>
          </view>
          <!-- 关联周边区域 -->
          <u-form-item
            :label="item.itemName"
            class="cell label-position-top"
            :required="item.formItemProps.required"
            :arrow="false"
            v-if="item.operateType == '91419'"
            :prop="item.checkKey"
          >
            <u-input
              :disabled="true"
              placeholder="请选择"
              slot="right-icon"
              v-model="form[item.checkKey]"
              @tap="handlerNearByGis(item)"
            />
          </u-form-item>
          <!-- 日期选择 -->
          <u-form-item
            :label="item.itemName"
            class="cell label-position-top map-icon"
            :required="item.formItemProps.required"
            :arrow="false"
            v-if="item.operateType == '91422'"
            :prop="item.checkKey"
          >
            <u-input
              :disabled="true"
              type="select"
              placeholder="请选择"
              v-model="form[item.checkKey]"
              @tap="choiceCalendar(item)"
            />
            <u-icon
              v-if="deathTrunOff"
              name="eye"
              :color="$theme.u_type_primary"
              size="44"
              @tap="handleGetDate(item)"
            ></u-icon>
          </u-form-item>

          <!-- TODO 经营场所坐标 -->
          <u-form-item
            :label="item.itemName"
            class="cell label-position-top map-icon"
            :required="item.formItemProps.required"
            :prop="item.checkKey"
            :arrow="false"
            v-if="item.operateType == '91407'"
          >
            <u-input
              :disabled="true"
              v-model="form[item.checkKey]"
              @tap="handleGpsInfo(item)"
            />
            <u-icon
              name="map-fill"
              :color="$theme.u_type_primary"
              size="44"
              @tap="handleGpsInfo(item)"
            ></u-icon>
          </u-form-item>
          <!-- TODO 所属网格 -->
          <u-form-item
            :label="item.itemName"
            class="cell label-position-top"
            :arrow="false"
            v-if="item.operateType == '91408'"
            :required="item.formItemProps.required"
            :prop="item.checkKeyLabel"
          >
            <!-- slot="right-icon"  -->
            <u-input
              :disabled="true"
              placeholder="请选择"
              type="select"
              v-model="form[item.checkKeyLabel]"
              @tap="handlerorgSelectShow(item)"
            >
            </u-input>
          </u-form-item>

          <!-- 图片上传 -->
          <u-form-item
            class="cell label-position-top"
            :label="item.itemName"
            :arrow="false"
            :required="item.formItemProps.required"
            v-if="item.operateType == '91405'"
          >
            <m-upload
              :fileList="item.fileList"
              uploadText="选择图片"
              :width="200"
              :height="200"
              :disabled="isDisabled"
              :deletable="!isDisabled"
              :index="item.itemUuid"
              :maxCount="1"
              :multiple="false"
              upApiUrl="uploadBase64File"
              :uploadParam="{ fiGroupCode: $FILE_GROUP_TYPE.m_check_attr }"
              @on-list-change="getImgs"
            >
            </m-upload>
          </u-form-item>
          <view v-show="form[item.checkKey] && item.operateType == '91401'">
            <u-form-item
              class="cell cell-sub"
              title="处理方式"
              :value="item.checkDataLabel"
              :arrow="true"
              :required="item.formItemProps.required"
              v-if="item.dealList && item.dealList.length > 0"
              @click="handlerShowSelect(item)"
            ></u-form-item>

            <view v-for="(record, rIdx) in item.workItems" :key="rIdx">
              <!-- 是否选择 -->
              <u-form-item
                class="cell cell-sub"
                :title="record.itemName"
                :arrow="false"
                v-if="record.operateType == '91401'"
              >
                <u-switch
                  :disabled="isDisabled"
                  slot="right-icon"
                  v-model="form[record.checkKey]"
                  @change="handlerSwitch"
                ></u-switch>
              </u-form-item>
              <!-- 添加卷烟 -->
              <u-form-item
                class="cell cell-sub"
                :title="record.itemName"
                :arrow="false"
                v-else-if="record.operateType == '91411'"
              >
                <u-icon
                  name="plus-circle"
                  :color="!isDisabled ? $theme.u_type_primary : '#c0c0c0'"
                  size="38"
                  slot="right-icon"
                  @tap="handlerAdd(record)"
                ></u-icon>
              </u-form-item>
              <!-- 收购人员登记 -->
              <u-form-item
                class="cell cell-sub"
                :title="record.itemName"
                :arrow="false"
                v-else-if="record.operateType == '91412'"
              >
                <u-icon
                  name="plus-circle"
                  :color="!isDisabled ? $theme.u_type_primary : '#c0c0c0'"
                  size="38"
                  slot="right-icon"
                  @tap="handlerAddPersons(record)"
                ></u-icon>
              </u-form-item>

              <!-- 图片上传 -->
              <u-form-item
                class="cell label-position-top"
                :title="record.itemName"
                :arrow="false"
                v-if="record.operateType == '91405'"
              >
                <m-upload
                  :fileList="record.fileList"
                  uploadText="选择图片"
                  :width="200"
                  :height="200"
                  :disabled="isDisabled"
                  :deletable="!isDisabled"
                  :index="record.itemUuid"
                  :maxCount="1"
                  :multiple="false"
                  upApiUrl="uploadBase64File"
                  :uploadParam="{ fiGroupCode: $FILE_GROUP_TYPE.m_check_attr }"
                  slot="right-icon"
                  @on-list-change="getImgs"
                >
                </m-upload>
              </u-form-item>

              <view
                style="padding-left: 10px"
                v-if="personsMap[record.itemUuid]"
              >
                <u-row
                  gutter="16"
                  v-for="(pItem, pIdx) in personsMap[record.itemUuid]"
                  :key="pIdx"
                >
                  <u-col span="9">
                    <view class="title">
                      {{ pItem.personName }}
                    </view>
                  </u-col>
                  <u-col span="3" style="text-align: center; display: flex">
                    <u-icon
                      name="edit-pen"
                      :color="$theme.u_type_primary"
                      size="32"
                      style="flex: 1"
                      v-if="!isDisabled"
                      @tap="handlerEditPerson(pItem, record.itemUuid)"
                    ></u-icon>
                    <u-icon
                      name="trash"
                      color="red"
                      size="32"
                      style="margin-left: 5px; flex: 1"
                      v-if="!isDisabled"
                      @tap="handlerDeletePerson(pItem, record.itemUuid)"
                    ></u-icon>
                  </u-col>
                </u-row>
              </view>

              <view
                v-for="(nRecord, nrIdx) in record.workItems"
                v-show="form[record.checkKey]"
                :key="nrIdx"
              >
                <u-input
                  style="margin: 5px 15px 5px 30px"
                  :placeholder="'请输入' + nRecord.itemName"
                  type="text"
                  :border="true"
                  v-model="nRecord.checkData"
                />
              </view>
            </view>
          </view>
          <u-select
            :list="item.dealList"
            :mask-close-able="false"
            v-model="item.showSelect"
            @cancel="handlerCloseSelect(item)"
            @confirm="handlerConfirm($event, item)"
          ></u-select>
        </view>
      </u-form>
    </view>
    <!-- @cancel="handlerSelect" -->
    <u-select
      :list="dictList"
      :mask-close-able="false"
      v-model="dicShow"
      @confirm="handlerDicConfirm($event)"
    ></u-select>
    <u-popup mode="bottom" height="100%" border-radius="16" v-model="cyShow">
      <add-cy-person
        :cyData="cyPerson"
        :isDisabled="isDisabled"
        @back="handlerCyBack"
      ></add-cy-person>
    </u-popup>
    <u-popup
      mode="bottom"
      height="100%"
      border-radius="16"
      v-model="storageShow"
    >
      <add-storage
        :storageData="storageInfo"
        :recordItem="recordItem"
        :checkInfo="menuData.checkInfo"
        :isDisabled="isDisabled"
        @back="handlerStorageBack"
      ></add-storage>
    </u-popup>
    <u-popup mode="bottom" height="100%" border-radius="16" v-model="carShow">
      <add-car
        :carData="carInfo"
        :isDisabled="isDisabled"
        @back="handlerCarBack"
      ></add-car>
    </u-popup>
    <!-- 行政区划选择 -->
    <u-popup mode="bottom" height="80%" v-model="nativeNameSelectShow">
      <area-select @choose="nativeNameSelectShowComfir"></area-select>
    </u-popup>
    <!-- 组织机构选择 -->
    <u-popup mode="bottom" height="80%" v-model="orgSelectShow">
      <org-select
        :cleanParentOrg="true"
        limitNodeType="07"
        title="所属网格"
        tips="请选择所属网格"
        treeType="zm-all"
        @choose="handlerChooseOrg"
      ></org-select>
    </u-popup>
    <u-calendar
      :max-date="maxDate"
      v-model="calendarShow"
      @change="calendarConfirm('type', $event)"
    >
    </u-calendar>
  </view>
</template>
<script>
import addCyPerson from "./add-cy-person.vue";
import addCar from "./case-car.vue";
import moment from "moment";
import MUpload from "@/components/m-upload";
import addStorage from "./add-storage.vue";
import subListItem from "./sub-list-item.vue";
import zjCommonService from "@/service/common/common.service";
import areaSelect from "@/components/area-select.vue";
import OrgSelect from "@/components/org-select.vue";
import certificateService from "@/service/certificate/certificate.service.js";
import { M_CHECK_GROUP, L_SUBJECT_TYPE } from "@/service/check/mapping/enum.js";
import { dateUtils } from "@/common/util";

const FORM_ITEMS = {
  current_addr: {
    editable: true,
    required: true,
    rules: [
      {
        required: true,
        message: "请输入居住地址",
        trigger: ["change", "blur"],
      },
    ],
  },
  contact_mobile: {
    editable: true,
    required: true,
    rules: [
      {
        required: true,
        message: "请输入联系方式",
        trigger: ["change", "blur"],
      },
    ],
  },
  special_type: {
    editable: true,
  },
  business_addr: {
    readOnly: true,
  },
  env_type: {
    required: false,
  },
  biz_area: {
    editable: true,
  },
};

export default {
  name: "MaintainCom",
  components: {
    addCyPerson,
    subListItem,
    addCar,
    addStorage,
    areaSelect,
    MUpload,
    OrgSelect,
  },
  props: {
    menuData: {
      type: Object,
      default: () => {},
    },
    recordDatas: {
      type: Array,
      default: () => [],
    },
    isDisabled: {
      // 是否可编辑
      type: Boolean,
      default: false,
    },
    actionEvent: {
      type: Object,
      default: () => {},
    },
    checkGroup: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      calendarShow: false,
      peopleInfo: "",
      moment,
      records: this.recordDatas,
      form: {},
      cigsMap: {}, // 添加的问题卷烟信息
      addItemUuid: "", // 当前添加卷烟的指标
      preFix: "L", // 指标前缀
      mainLabelStyle: {
        // 'color': '#000',
        // 'fontWeight': '600',
      },
      maxDate: moment().format("YYYY-MM-DD"),
      retailerLicGis: [], // 零售户已关联的坐标
      dealMap: {}, // 处理方式字典
      personInfoOpen: false,
      personInfo: {}, // 嫌疑人信息
      personsMap: {}, // 添加的嫌疑人信息
      addSuspectUuid: "", // 当前点击添加嫌疑人指标项
      nativeNameSelectShow: false,
      dictList: this.$store.state.dicts["RETAILER_BUSI_TYPE"], // 商圈字典数据
      dicShow: false,
      recordItem: null, // 当前点击的指标项
      cyShow: false,
      storageShow: false,
      carShow: false,
      idCardInfo: {},
      deadDate: "",
      cyPerson: {}, // 从业人员
      cyPersons: this.menuData.personInfos || [],
      cars: this.menuData.vehicleInfoMts || [],
      carInfo: {}, // 车辆信息
      storages: this.menuData.storageInfos || [],
      storageInfo: {}, // 仓储信息
      reIntoItem: undefined,
      orgSelectShow:false,
      supplyList:this.menuData.supplySources || [],
      flagIdCard: true,
      uuidList: [
        "34020602",
        "34020601",
        "34020603",
        "34020604",
        "34020605",
        "34020610",
      ], // 对于零售户id不可编辑
      readUuid: ["34020623", "34020609"], // 无论零售户还是无证户 id不可编辑
      delPersonUuids: [], // 从业人员删除
	// h5端部分浏览器input设置disabled后点击事件失效 2023-10-25 fsx start
	pointerStyle: {
	  marginRight: "5px",
		pointerEvents: "none !important"
	},
	// h5端部分浏览器input设置disabled后点击事件失效 2023-10-25 fsx start
	rules: {},
	deathTrunOff: false, // 是否开启同步第三方零持证人死亡或丧失行为能力日期查询功能
    }
  },
  watch: {
    menuData(v) {
      console.log("监听", v);
      this.delPersonUuids = v.delPersonUuids || [];
      if (v.refeshGis) {
        // this.queryRetailerGis();
      }
      if (v.supplySources) {
        // 去重
        let retailers = [];
        v.supplySources.forEach((r) => {
          let existR = this.supplyList.filter(
            (rc) => rc.retailerUuid == r.retailerUuid
          );
          existR.length == 0 && retailers.push(r);
        });

        this.supplyList = [...this.supplyList, ...retailers];
      }
    },
    actionEvent(v) {
      if (v.event == "pos" && this.reIntoItem) {
        let keyLabel = this.preFix + this.reIntoItem.itemUuid;
        this.form[keyLabel] = v.value.longitude + "," + v.value.latitude;
      }
    },
    rules: {
      handler() {
        this.$nextTick(() => {
          this.$refs.uForm.setRules(this.rules);
        });
      },
      deep: true,
    },
  },
  mounted() {
    this.initDeath();
  },
  created() {
    this.initData();
    // 还原检查项数据
    let storageRecordMap = {};
    this.menuData.records.forEach((r) => {
      storageRecordMap[this.preFix + r.itemUuid] = r.checkData;

    });
    let dicts = this.$store.state.dicts["M_CHECK_HANDLE_RESULT"];
    dicts.forEach((d) => (this.dealMap[d.bcbCode] = d.bcbName));
    this.records.forEach((r) => {
      r.checkKey = this.preFix + r.itemUuid;

      r.formItemProps = FORM_ITEMS[r.attrCode] || {};

      let st1 =
        storageRecordMap[r.checkKey] ||
        r.checkData ||
        (r.operateType == "91401" ? r.defaultValue == "true" : "");
      if (r.operateType == "91401" && typeof st1 == "string") {
        st1 = st1 == "true";
      }
      this.$set(this.form, r.checkKey, st1);
      this.$set(this.rules, r.checkKey, r.formItemProps.rules || []);
      if (r.operateType == "91402") {
        // 选项这种 需要设置checkKeyLabel
        r.checkKeyLabel = this.preFix + r.itemUuid + "Str";
        if (this.form[r.checkKey]) {
          this.$set(
            this.form,
            r.checkKeyLabel,
            this.$u.dic.getDicNameByKeyCode(
              r.contentOptions,
              this.form[r.checkKey]
            )
          );
          this.$set(this.rules, r.checkKeyLabel, r.formItemProps.rules || []);
        }
      } else if (r.operateType == "91406") {
        // 区划选择
        r.checkKeyLabel = this.preFix + r.itemUuid + "Str";
        if (this.form[r.checkKey]) {
          let arCodeArr = this.form[r.checkKey].split(",");
          let result = zjCommonService.getPersonLocal(
            arCodeArr[arCodeArr.length - 1],
            true
          );
          if (this.$modal.isMuniCity(result.proCode)) {
            this.$set(
              this.form,
              r.checkKeyLabel,
              result.length == 0
                ? ""
                : [result.admdivName, result.countryName].join("")
            );
          } else {
            this.$set(
              this.form,
              r.checkKeyLabel,
              result.length == 0
                ? ""
                : [result.proName, result.admdivName, result.countryName].join(
                    ""
                  )
            );
          }
        }
        this.$set(this.rules, r.checkKeyLabel, r.formItemProps.rules || []);
      } else if (r.operateType == "91405") {
        r.fileList = [];
        if (this.form[r.checkKey]) {
          r.fileList.push({
            gfiId: this.form[r.checkKey],
          });
        }
      } else if (r.operateType == "91408") {
        // 所属网格
        r.checkKeyLabel = this.preFix + r.itemUuid + "Str";
        if (this.form[r.checkKey]) {
          zjCommonService
            .getOrgs(this.form[r.checkKey])
            .then((res) => {
              if (res.success) {
                this.$set(this.form, r.checkKeyLabel, res.data[0].orgName);
              } else {
                this.$modal.alert(res.msg);
              }
            })
            .catch((error) => {
              this.$modal.alert(error);
            });
        }
        this.$set(this.rules, r.checkKeyLabel, r.formItemProps.rules || []);
      }
      // 子项
      r.workItems &&
        r.workItems.forEach((nr) => {
          nr.checkKey = this.preFix + nr.itemUuid;
          let st =
            storageRecordMap[nr.checkKey] ||
            nr.checkData ||
            (nr.operateType == "91401" ? nr.defaultValue == "true" : "");
          if (nr.operateType == "91401" && typeof st == "string") {
            st = st == "true";
          }
          this.$set(this.form, nr.checkKey, st);
          if (nr.operateType == "91402") {
            // 选项这种 需要设置checkKeyLabel
            nr.checkKeyLabel = this.preFix + nr.itemUuid + "Str";
            if (this.form[nr.checkKey]) {
              this.$set(
                this.form,
                nr.checkKeyLabel,
                this.$u.dic.getDicNameByKeyCode(
                  nr.contentOptions,
                  this.form[nr.checkKey]
                )
              );
            }
          } else if (nr.operateType == "91406") {
            // 区划选择
            nr.checkKeyLabel = this.preFix + nr.itemUuid + "Str";
            if (this.form[nr.checkKey]) {
              let arCodeArr = this.form[nr.checkKey].split(",");
              let result = zjCommonService.getPersonLocal(
                arCodeArr[arCodeArr.length - 1],
                true
              );
              this.$set(
                this.form,
                nr.checkKeyLabel,
                result.length == 0
                  ? ""
                  : [
                      result.proName,
                      result.admdivName,
                      result.countryName,
                    ].join("")
              );
            }
          } else if (nr.operateType == "91405") {
            nr.fileList = [];
            if (this.form[nr.checkKey]) {
              nr.fileList.push({
                gfiId: this.form[nr.checkKey],
              });
            }
          }
        });
      // 处理方式
      if (r.jgsxDealUuidZj) {
        r.dealList = [];
        r.jgsxDealUuidZj.split(",").forEach((j) =>
          r.dealList.push({
            label: this.dealMap[j],
            value: j,
            itemUuid: r.itemUuid,
          })
        );
      }
    });
  },
  methods: {
    // 判断是否有开启死亡日期更新开关
    initDeath() {
      zjCommonService
        .getSysConfig("RLIC_SYS", "deadPopulationInformation")
        .then((d) => {
          if (d.success && d.msg) {
            this.deathTrunOff = true;
          } else {
            this.deathTrunOff = false;
          }
        });
    },

    initData() {
      this.storages.forEach((item) => {
        item.uuid = item.storageUuid;
      });
      this.cyPersons.forEach((item) => {
        if(!!item.personUuid) {
          item.uuid = item.personUuid;
        } 
      });
      this.cars.forEach((item) => {
        // item.uuid = item.carUuid;
        if(!!item.carUuid) {
          item.uuid = item.carUuid;
        }  
      });
    },
    //
    handleGpsInfo(itm) {
      let checkVal = this.form[this.preFix + itm.itemUuid];
      let lat = "";
      let lng = "";
      if (this.isDisabled) {
        // #ifdef H5-DINGDING
        if(checkVal){
          let checkInfoTmp = this.menuData.checkInfo;
          let latlng = checkVal.split(",");
          try {
            lng = latlng[0];
            lat = latlng[1];
            this.$deviceApi.navigateMap(
              lat,
              lng,
              checkInfoTmp.taskSubject == L_SUBJECT_TYPE.RETAILER
                ? checkInfoTmp.companyName
                : `${checkInfoTmp.companyName}(无证户)`
            );
          } catch (e) {
            console.log(e);
          }
        }
        // #endif
        return;
      }
      if (checkVal) {
        let latlng = checkVal.split(",");
        try {
          lng = latlng[0];
          lat = latlng[1];
        }catch(e){
          console.log(e);
        }
      }
      // #ifdef H5-DINGDING
      this.reIntoItem = itm;
      console.log(lat + "======" + lng);
      this.$deviceApi
        .getLocationByMap(lat, lng, 1000)
        .then((res) => {
          this.form[this.preFix + itm.itemUuid] = res[1] + "," + res[0];
        })
        .catch((e) => {
          console.log(e + JSON.stringify(e));
          this.$modal.toast("定位失败");
        });
      // #endif

      // #ifndef H5-DINGDING
      this.reIntoItem = itm;
      this.$u.route("pages/commonPage/modifyLocationMap");
      // #endif
    },
    // 是否选中
    handlerSwitch(isChecked, ck) {},
    vaildUuidList(itemUuid) {
      return (
        this.readUuid.includes(itemUuid) ||
        (this.uuidList.includes(itemUuid) &&
          this.checkGroup != M_CHECK_GROUP.NOLICENSE)
      );
    },
    // 显示通用选择框
    handlerSelShow (item) {
      if (this.vaildUuidList(item.itemUuid)) return;
      if (this.isDisabled) {
        return false;
      }
      this.recordItem = item;
      this.dictList = this.$store.state.dicts[item.contentOptions];
      this.dicShow = true;
    },
    handlerAreaShow (item) {
      if (this.vaildUuidList(item.itemUuid)) return;
      if (this.isDisabled) {
        return false;
      }
      this.recordItem = item;
      this.nativeNameSelectShow = true;
    },
    // 选择所属网格
    handlerorgSelectShow(item){
      if (this.isDisabled) {
        return false;
      }
      this.recordItem = item;
      this.orgSelectShow = true;
    },
    getImgs(list, index){
      for (let i = 0; i < this.records.length; i++) {
        let r = this.records[i];
        if(r.itemUuid == index){
          r.fileList = list;
          if(list.length > 0){
            r.checkData = list[0].gfiId;
            this.form[this.preFix + r.itemUuid] = list[0].gfiId;
          } else {
            r.checkData = "";
            this.form[this.preFix + r.itemUuid] = "";
          }
          return;
        }
        if(r.workItems && r.workItems){
          for (let j = 0; j < r.workItems.length; j++) {
            let cr = r.workItems[j];
            if(cr.itemUuid == index){
              cr.fileList = list;
              if(list.length > 0){
                cr.checkData = list[0].gfiId;
                this.form[this.preFix + cr.itemUuid] = list[0].gfiId;
              } else {
                cr.checkData = "";
                this.form[this.preFix + cr.itemUuid] = "";
              }
              return;
            }
          }
        }
      }
    },
    nativeNameSelectShowComfir(areas) {
      for (let k = 0; k < this.records.length; k++) {
        if (this.records[k].itemUuid === this.recordItem.itemUuid) {
          // this.records[k].checkData = [areas[0].proCode, areas[0].admdivCode, areas[0].countryCode,].join(
          //   ",");
          this.records[k].checkData = areas[0].areaCode;
          if (this.$modal.isMuniCity(areas[0].proCode)) {
            this.form[this.recordItem.checkKeyLabel] = [
              areas[0].admdivName,
              areas[0].countryName,
            ].join("");
          } else {
            this.form[this.recordItem.checkKeyLabel] = [
              areas[0].proName,
              areas[0].admdivName,
              areas[0].countryName,
            ].join("");
          }

          this.form[this.recordItem.checkKey] = areas[0].areaCode;
          break;
        }
      }
      this.nativeNameSelectShow = false;
    },
    // 登记单位回调事件
    handlerChooseOrg(orgs) {
      for (let k = 0; k < this.records.length; k++) {
        if (this.records[k].itemUuid === this.recordItem.itemUuid) {
          this.records[k].checkData = orgs[0].id;
          this.form[this.recordItem.checkKey] = orgs[0].id;
          this.form[this.recordItem.checkKeyLabel] = orgs[0].name;
          this.orgSelectShow = false;
        }
      }
    },
    // 显示选择处理方式
    handlerShowSelect(item) {
      item.showSelect = true;
      this.$forceUpdate();
    },
    // 关闭处理方式选择框
    handlerCloseSelect(item) {
      item.showSelect = false;
      this.$forceUpdate();
    },
    // 处理方式
    handlerConfirm(e, item) {
      console.log(e, item);
      item.checkData = e[0].value;
      item.checkDataLabel = e[0].label;
      item.showSelect = false;
      this.$forceUpdate();
    },
    // 选择地理环境
    handlerBusiSelect() {
      this.dicShow = false;
      this.$forceUpdate();
    },
    // 地理环境
    handlerDicConfirm(e) {
      for (let k = 0; k < this.records.length; k++) {
        if (this.records[k].itemUuid === this.recordItem.itemUuid) {
          this.records[k].checkData = e[0].value;
          this.records[k].checkDataLabel = e[0].label;
          this.form[this.recordItem.checkKeyLabel] = e[0].label;
          this.form[this.recordItem.checkKey] = e[0].value;
          break;
        }
      }
      this.dicShow = false;
    },
    // 添加疑似收购人员
    handlerAddPersons(rc) {
      if (this.isDisabled) {
        return false;
      }
      console.log("添加疑似收购人员", rc);
      this.addSuspectUuid = rc.itemUuid;
      this.personInfoOpen = true;
    },
    // 添加从业人员
    handlerAddCy(item) {
      if (this.isDisabled) {
        return false;
      }
      this.recordItem = item;
      this.cyPerson = {};
      this.cyShow = true;
    },
    // 添加仓储信息
    handlerAddStorage(item) {
      if (this.isDisabled) {
        return false;
      }
      this.recordItem = item;
      this.storageInfo = {};
      this.storageShow = true;
    },
    // 添加车辆信息
    handlerAddCar(item) {
      if (this.isDisabled) {
        return false;
      }
      this.recordItem = item;
      this.carInfo = {};
      this.carShow = true;
    },
    // 添加供货来源
    handlerAddSupply(item) {
      if (this.isDisabled) {
        return false;
      }
      this.recordItem = item;
      this.setRouteParam(this.supplyList);
      this.$u.route(
        "/pages/check/temporaryTask?taskSubject=01&title=选择货源来源"
      );
    },
    // 确定
    handlerSure() {
      this.$refs.uForm.validate((valid) => {
        if (valid) {
          if (!this.flagIdCard) {
            this.$modal.alert("请输入正确的身份证！");
            return;
          }
          let comData = {
            records: this.records,
            comType: this.menuData.type,
            personInfos: this.cyPersons,
            storageInfos: this.storages,
            vehicleInfoMts: this.cars,
            supplySources: this.supplyList,
            delPersonUuids: this.delPersonUuids,
          };
          // 处理数据
          this.recursive(this.records);
          console.log("处理后的数据", this.records);
          this.$emit("ok", comData);
        }
      });
    },
    // 验证身份证
    validText(e, checkKey) {
      if (checkKey == "L34020604") {
        if (!this.$u.test.isEmpty(e)) {
          this.flagIdCard = this.$u.test.idCard(e);
          if (!this.flagIdCard) this.$modal.alert("请输入正确的身份证！");
        }
      }
    },
    // 递归赋值选中项
    recursive(arr) {
      arr.forEach((item) => {
        item.checkData = this.form[this.preFix + item.itemUuid];
        if (item.workItems) {
          this.recursive(item.workItems);
        }
      });
    },
    // 关闭
    handlerBack() {
      this.$emit("close", true);
    },
    // 编辑嫌疑人信息
    handlerEditPerson(pInfo, pItemUuid) {
      this.personInfo = pInfo;
      this.addSuspectUuid = pItemUuid;
      this.personInfoOpen = true;
    },
    // 删除嫌疑人
    handlerDeletePerson(pInfo, pItemUuid) {
      this.$modal.confirm(`确定删除【${pInfo.personName}】吗?`, () => {
        this.personsMap[pItemUuid] = this.personsMap[pItemUuid].filter(
          (c) => c.uuid != pInfo.uuid
        );
        this.$forceUpdate();
      });
    },
    // 编辑列表项
    handlerEditListItem(da) {
      if (da.recordUuid == "34020638") {
        // 从业人员
        this.cyPerson = da.item;
        this.cyShow = true;
      } else if (da.recordUuid == "34020639") {
        // 供货来源
        // 没有编辑
      } else if (da.recordUuid == "34020641") {
        // 仓储信息
        this.storageInfo = da.item;
        this.storageShow = true;
      } else if (da.recordUuid == "34020640") {
        // 车辆信息
        this.carInfo = da.item;
        this.carShow = true;
      }
    },
    // 删除列表项
    handlerDelListItem(da) {
      this.$modal.confirm("确定删除吗？", () => {
        if (da.recordUuid == "34020638") {
          // 从业人员
          let delArr = this.cyPersons.filter((p) => p.uuid == da.item.uuid);
          if (delArr && delArr.length > 0 && delArr[0].uuid) {
            this.delPersonUuids.push(delArr[0].uuid);
          }
          this.cyPersons = this.cyPersons.filter((p) => p.uuid != da.item.uuid);
          this.cyShow = false;
        } else if (da.recordUuid == "34020639") {
          // 供货来源
          this.supplyList = this.supplyList.filter(
            (s) => s.retailerUuid != da.item.retailerUuid
          );
        } else if (da.recordUuid == "34020641") {
          // 仓储信息
          this.storages = this.storages.filter((p) => p.uuid != da.item.uuid);
          this.storageShow = false;
        } else if (da.recordUuid == "34020640") {
          // 车辆信息
          this.cars = this.cars.filter((p) => p.uuid != da.item.uuid);
          this.carShow = false;
        }
      });
    },
    handlerOpen(idx, sItemUuid) {
      this.cigsMap[sItemUuid].map((c, i) => {
        c.show = i == idx;
      });
      this.$forceUpdate();
    },
    // 关闭从业人员登记
    handlerCyBack(p) {
      if (p) {
        !p.uuid && (p.uuid = new Date().getTime());
        p.itemUuid = this.addSuspectUuid;
        p.checkUuid = this.menuData.checkInfo.checkUuid;
        p.retailerUuid = this.menuData.checkInfo.retailerUuid;
        this.cyPersons = this.cyPersons.filter(c => c.uuid != p.uuid);
        this.cyPersons.push(p);
      }
      this.cyShow = false;
      this.$forceUpdate();
    },
    // 关闭车辆信息登记
    handlerCarBack(p) {
      if (p) {
        !p.uuid && (p.uuid = new Date().getTime());
        p.itemUuid = this.addSuspectUuid;
        p.checkUuid = this.menuData.checkInfo.checkUuid;
        p.retailerUuid = this.menuData.checkInfo.retailerUuid;
        this.cars = this.cars.filter((c) => c.uuid != p.uuid);
        this.cars.push(p);
      }
      this.carShow = false;
      this.$forceUpdate();
    },
    // 关闭仓储信息登记
    handlerStorageBack(p) {
      if (p) {
        !p.uuid && (p.uuid = new Date().getTime());
        p.itemUuid = this.addSuspectUuid;
        p.checkUuid = this.menuData.checkInfo.checkUuid;
        p.retailerUuid = this.menuData.checkInfo.retailerUuid;
        this.storages = this.storages.filter((c) => c.uuid != p.uuid);
        this.storages.push(p);
      }
      this.storageShow = false;
      this.$forceUpdate();
    },
    // 查询当前零售户已关联的坐标
    queryRetailerGis() {
      zjCommonService
        .getRetailerLicGis(this.menuData.checkInfo.retailerUuid)
        .then((dr) => {
          if (dr.success) {
            this.retailerLicGis = dr.data || [];
            let relGis = [];
            this.retailerLicGis.forEach((g) => relGis.push(g.gisName));
            this.form[this.preFix + "34021005"] = relGis.join(",");
          }
        });
    },
    calendarConfirm(type, e) {
      for (let k = 0; k < this.records.length; k++) {
        if (this.records[k].itemUuid === this.recordItem.itemUuid) {
          this.records[k].checkData = moment(e.result).format("YYYY-MM-DD");

          this.form[this.recordItem.checkKey] = moment(e.result).format(
            "YYYY-MM-DD"
          );

          break;
        }
      }
      this.calendarShow = false;
    },

    choiceCalendar(item) {
      if (this.isDisabled) {
        return;
      }
      this.calendarShow = true;
      if (this.vaildUuidList(item.itemUuid)) return;
      if (this.isDisabled) {
        return false;
      }
      this.recordItem = item;
    },
    handleGetDate() {
      if (this.isDisabled) {
        return;
      }
      let parmas = {
        cardId: this.form["L34020604"], // 身份证号
      };
      certificateService
        .getDeadInfo(parmas)
        .then((res) => {
          if (res.success) {
            this.peopleInfo = res.bean.deadDate;
            if (this.peopleInfo) {
              this.deadDate = moment(this.peopleInfo).format("YYYY-MM-DD");
              this.$set(this.form, "L34020646", this.deadDate);
            } else {
              this.$u.toast("未查询到死亡人口信息");
              this.$set(this.form, "L34020646", "");
            }
          }
        })
        .catch((err) => {
          this.$u.toast("err");
        });
    },
    // 显示周边区域
    handlerNearByGis() {
      if (this.isDisabled) {
        return;
      }
      this.setRouteParam({
        retailer: this.menuData.checkInfo, // 持证户信息
        retailerLicGis: this.retailerLicGis, // 零售户已关联的坐标
      });
      this.$u.route("/pages/check/poiCollect/surroundingsGis");
    },
  },
}
</script>
<style lang="scss" scoped>

.title {
	font-size: 15px;
	color: #666;
	font-weight: 600;
	margin: 5px 10px;
}
.fpad {
  padding: 20rpx 20rpx;
}

.sub-title {
	color: #666;
	margin: 3px 10px;
}
.label-position-top{
	display: block !important;
}
/deep/.map-icon .u-cell__value{
	float: right !important;
	padding-top: 5px !important;
}
</style>
